package com.sdap2.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sdap2.entity.Device;
import com.sdap2.entity.enums.DeviceType;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;

@Data
public class DeviceListDTO {
    private Long id;
    private String name;
    private String serialNumber;
    private DeviceType deviceType;
    private String unit;
    private String description;
    private String monitorUrl;
    private Integer status;
    private Long greenhouseId;
    private String greenhouseName;
    private String boxNo;
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    
    public static DeviceListDTO fromEntity(Device device) {
        DeviceListDTO dto = new DeviceListDTO();
        BeanUtils.copyProperties(device, dto);
        if (device.getGreenhouse() != null) {
            dto.setGreenhouseId(device.getGreenhouse().getId());
            dto.setGreenhouseName(device.getGreenhouse().getName());
            dto.setBoxNo(device.getGreenhouse().getBoxNo());
        }
        return dto;
    }
} 